﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Server.Model;
using Server.Data;

namespace Server.Biz {
    /// <summary>
    /// 这个类主要用于接收来自家长的命令：锁屏，截屏，审批计划，否认计划
    /// </summary>
    public class CommandService:BaseService {
        CommandDAO dao = null;
        public CommandService() {
            dao = new CommandDAO();
        }

        /// <summary>
        /// 家长指定机器状态
        /// </summary>
        /// <param name="pStatus"></param>
        /// <param name="pClientID"></param>
        /// <param name="pUserID"></param>
        /// <param name="pUserName"></param>
        public void SetCommand(Status pStatus, long pClientID, long pUserID, string pUserName) 
        {
            dao.SetCommand(pStatus, pClientID, pUserID, pUserName);
        }

        /// <summary>
        /// 获取指定客户端当前状态
        /// </summary>
        /// <param name="pClientID"></param>
        /// <param name="pOperID"></param>
        /// <param name="pOperName"></param>
        /// <returns></returns>
        public Status? GetStatus(long pClientID, long pOperID, string pOperName)
        {
            Status? ret = null;
            string status = dao.GetStatus(pClientID, pOperID, pOperName);
            if (!string.IsNullOrEmpty(status))
            {
                ret = (Status)Enum.Parse(typeof(Status), status);
            }

            return ret;
        }

        /// <summary>
        /// 获取指定客户端状态历史信息
        /// </summary>
        /// <param name="pClientID"></param>
        /// <returns></returns>
        public List<StatusHistory> GetStatusHistory(long pClientID)
        {
            return dao.GetStatusHistory(pClientID);
        }

        /// <summary>
        /// 更新状态（客户端调用），并返回最新的指定状态
        /// </summary>
        /// <param name="pStatus"></param>
        /// <param name="pClientID"></param>
        /// <param name="pOperID"></param>
        /// <param name="pOperName"></param>
        /// <returns>如果有新的命令来更改状态返回对应的更改状态，如果没有返回null</returns>
        public Status? UpdateStatusAndGetLatestedCommand(Status pStatus, long pClientID, long pOperID, string pOperName)
        {
            dao.UpdateStatus(pStatus, pClientID, pOperID, pOperName);
            return this.GetStatus(pClientID, pOperID, pOperName);
        }
    }
}
